package com.example.app.pages.main.home.addNew.addRecord

import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.isImeVisible
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.AttachMoney
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import coloredShadow
import com.example.app.addRecordViewModel
import com.example.app.components.MyIcon.MyIcon
import com.example.app.components.MyListItem.MyListItem
import com.example.app.components.MyText.MyText
import com.example.app.components.MyTextField.MyTextField
import com.example.app.pages.main.home.addNew.addRecord.viewModel.AddRecordViewModel
import com.example.app.ui.theme.shapeMedium
import kotlinx.coroutines.launch

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun IncomeInput() {
    var incomeMoneyTextFieldValue =
        addRecordViewModel.incomeMoneyInputState.textFieldValue.collectAsState()



    MyListItem(colors = ListItemDefaults.colors(containerColor = Color.Transparent),
        headlineContent = {

            MyTextField(
                shadow = Modifier.coloredShadow(
                    borderRadius = shapeMedium,
                    blurRadius = 16.dp,
                    offsetY = -16.dp,
                    offsetX = 0.dp,
                    color = MaterialTheme.colorScheme.onSurface.copy(alpha = .1f)
                ),
                colors = OutlinedTextFieldDefaults.colors(
                    errorContainerColor = MaterialTheme.colorScheme.surface,
                    errorLabelColor = MaterialTheme.colorScheme.surface,
                    focusedLabelColor = MaterialTheme.colorScheme.surface,
                    focusedContainerColor = MaterialTheme.colorScheme.surface,
                    unfocusedContainerColor = MaterialTheme.colorScheme.surface,
                    unfocusedBorderColor = Color.Transparent,
                    focusedPlaceholderColor = OutlinedTextFieldDefaults.colors().focusedPlaceholderColor.copy(
                        .3f
                    ),
                    unfocusedLabelColor = OutlinedTextFieldDefaults.colors().focusedPlaceholderColor.copy(
                        .3f
                    ),
                    focusedBorderColor = Color.Transparent,
                    cursorColor = MaterialTheme.colorScheme.outline
                ),
                myTextFieldState = addRecordViewModel.incomeMoneyInputState,
                leadingIcon = {
                    MyIcon(imageVector = Icons.Rounded.AttachMoney)
                },
                placeholder = {
                    MyText(text = "请输入收入金额")
                },
                value = incomeMoneyTextFieldValue.value,
                onValueChange = {
                    addRecordViewModel.incomeMoneyInputState.flowUpdate_textFieldValue(it)
                },
                label = {
                    MyText(text = "收入")
                },
                isError = false
            )
        })
}